From 100723a89eb5f83df26dfdc30cac6a38e2eaec85 Mon Sep 17 00:00:00 2001 From: "kaf24@scramble.cl.cam.ac.uk" Date: Thu, 25 Nov 2004 11:45:09 +0000 Subject: [PATCH] bitkeeper revision 1.1159.194.1 (41a5c5c5J8BRAOOMMsDGqEcd_8brmg) Sort exception tables during Xen boot. This will fix some nasty crashes that some people have seen in the last day or so. --- xen/arch/x86/extable.c | 36 +++++++++++++++++++++++----- xen/arch/x86/setup.c | 2 ++ xen/include/asm-x86/x86_32/uaccess.h | 1 + 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/xen/arch/x86/extable.c b/xen/arch/x86/extable.c index 54251cc3c5..d3292027e0 100644 --- a/xen/arch/x86/extable.c +++ b/xen/arch/x86/extable.c @@ -3,6 +3,36 @@ #include #include +extern struct exception_table_entry __start___ex_table[]; +extern struct exception_table_entry __stop___ex_table[]; +extern struct exception_table_entry __start___pre_ex_table[]; +extern struct exception_table_entry __stop___pre_ex_table[]; + +static void sort_exception_table(struct exception_table_entry *start, + struct exception_table_entry *end) +{ + struct exception_table_entry *p, *q, tmp; + + for ( p = start; p < end; p++ ) + { + for ( q = p-1; q > start; q-- ) + if ( p->insn > q->insn ) + break; + if ( ++q != p ) + { + tmp = *p; + memmove(q+1, q, (p-q)*sizeof(*p)); + *q = tmp; + } + } +} + +void sort_exception_tables(void) +{ + sort_exception_table(__start___ex_table, __stop___ex_table); + sort_exception_table(__start___pre_ex_table, __stop___pre_ex_table); +} + static inline unsigned long search_one_table(const struct exception_table_entry *first, const struct exception_table_entry *last, @@ -28,21 +58,15 @@ search_one_table(const struct exception_table_entry *first, unsigned long search_exception_table(unsigned long addr) { - extern const struct exception_table_entry __start___ex_table[]; - extern const struct exception_table_entry __stop___ex_table[]; return search_one_table( __start___ex_table, __stop___ex_table-1, addr); } -#ifdef __i386__ unsigned long search_pre_exception_table(unsigned long addr) { - extern const struct exception_table_entry __start___pre_ex_table[]; - extern const struct exception_table_entry __stop___pre_ex_table[]; unsigned long fixup = search_one_table( __start___pre_ex_table, __stop___pre_ex_table-1, addr); DPRINTK("Pre-exception: %08lx -> %08lx\n", addr, fixup); return fixup; } -#endif diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 7ed4bf0744..cf6f7980e1 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -326,6 +326,8 @@ void __init start_of_day(void) if ( opt_watchdog ) nmi_watchdog = NMI_LOCAL_APIC; + sort_exception_tables(); + /* Tell the PCI layer not to allocate too close to the RAM area.. */ low_mem_size = ((max_page << PAGE_SHIFT) + 0xfffff) & ~0xfffff; if ( low_mem_size > pci_mem_start ) pci_mem_start = low_mem_size; diff --git a/xen/include/asm-x86/x86_32/uaccess.h b/xen/include/asm-x86/x86_32/uaccess.h index 1b1b28bfe5..7531a29445 100644 --- a/xen/include/asm-x86/x86_32/uaccess.h +++ b/xen/include/asm-x86/x86_32/uaccess.h @@ -85,6 +85,7 @@ struct exception_table_entry }; extern unsigned long search_exception_table(unsigned long); +extern void sort_exception_tables(void); /** * get_user: - Get a simple variable from user space. -- 2.30.2